<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>手风琴</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        li{
            list-style: none;
        }
        div{
            width: 520px;
            height: 280px;
            overflow: hidden;
            position: relative;
            margin: 0 auto;
        }
        div ul{
            position: absolute;
            left: 0;
            top: 0;
            z-index: 1;
        }
        div li{
            position: absolute;
            top: 0;left: 0;
        }
    </style>
</head>
<body>
    <div>
        <ol>
            <li><img src="https://img.alicdn.com/simba/img/TB10IlYOFXXXXaDXXXXSutbFXXX.jpg" alt=""></li>
            <li><img src="https://img.alicdn.com/simba/img/TB1psurOFXXXXXnXpXXSutbFXXX.jpg" alt=""></li>
            <li><img src="https://img.alicdn.com/simba/img/TB1cgsOOXXXXXaCXFXXSutbFXXX.jpg" alt=""></li>
            <li><img src="https://img.alicdn.com/tps/TB1aQ3tOFXXXXXwXFXXXXXXXXXX-520-280.jpg_.webp" alt=""></li>
            <li><img src="https://img.alicdn.com/tps/TB1vhIfOFXXXXbTXVXXXXXXXXXX-520-280.jpg_.webp" alt=""></li>
        </ol>
    </div>
    <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
    <script>
        var aLi = document.querySelectorAll('li');
        console.log(aLi);
        var aLiW = aLi[0].offsetWidth;
        console.log(aLiW)
        var spacing = 30;

        for(var i=1;i<aLi.length;i++){
            aLi[i].style.left = (aLiW-spacing*(aLi.length-1))+(i-1)*30+'px'
        }

        for(var i=0;i<aLi.length;i++){
            
            aLi[i].index = i;
            aLi[i].onmouseover = function (){
                for(var i=0;i<aLi.length;i++){
                    if( i <= this.index ){
                        console.log(this.index);
                        $(aLi[i]).stop(true,true).animate({
                            'left':  i*30+'px'
                        });
                    }else{
                        $(aLi[i]).stop(true,true).animate({
                            'left':  (aLiW-spacing*(aLi.length-1))+(i-1)*30+'px'
                        });
                    }
                }
            };
        }
    </script>
</body>
</html>